package com.atguigu.lease.web.app.service.impl;

import com.atguigu.lease.model.entity.ApartmentInfo;
import com.atguigu.lease.model.entity.GraphInfo;
import com.atguigu.lease.model.entity.LabelInfo;
import com.atguigu.lease.model.entity.ViewAppointment;
import com.atguigu.lease.web.app.mapper.ApartmentInfoMapper;
import com.atguigu.lease.web.app.mapper.ViewAppointmentMapper;
import com.atguigu.lease.web.app.service.*;
import com.atguigu.lease.web.app.vo.apartment.ApartmentItemVo;
import com.atguigu.lease.web.app.vo.appointment.AppointmentDetailVo;
import com.atguigu.lease.web.app.vo.appointment.AppointmentItemVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @author liubo
 * @description 针对表【view_appointment(预约看房信息表)】的数据库操作Service实现
 * @createDate 2023-07-26 11:12:39
 */
@Service
public class ViewAppointmentServiceImpl extends ServiceImpl<ViewAppointmentMapper, ViewAppointment>
        implements ViewAppointmentService {
    @Autowired
    private ViewAppointmentMapper viewAppointmentMapper;

    @Autowired
    private  ApartmentInfoService apartmentInfoService;


    /**
     * 查询个人预约看房列表
     * @return
     */
    @Override
    public List<AppointmentItemVo> viewAppointmentList(String userName) {


        return viewAppointmentMapper.viewAppointmentList(userName);
    }

    /**
     * 根据id查询预约信息，根据id做数据回显的
     * @param id
     * @return
     */
    @Override
    public AppointmentDetailVo getAppointmentDetailById(Long id) {
        /*
        这种回显数据一般都是分部查询的
        1、先获取基本数据
        2、再对应获取复杂的信息
         */

        //实例化一个返回对象
        AppointmentDetailVo detailVo = new AppointmentDetailVo();
        //先获取预约的基本信息
        ViewAppointment appointment = this.getById(id);
        System.out.println(appointment + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
        //属性对拷
        BeanUtils.copyProperties(appointment, detailVo);

        //实例化一个公寓详情的对象
        ApartmentItemVo apartmentItemVo = apartmentInfoService.getApartmentDetailById(appointment.getApartmentId());

        detailVo.setApartmentItemVo(apartmentItemVo);
        System.out.println(detailVo);
        return detailVo;
    }
}





